import java.util.Scanner;

/**
 * @author jingluo
 */
public class GuessNumber {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input;
        do {
            int random = (int) (Math.random() * 100 + 1);
            int i = 7;
            for (int j = 0; j < i; j++) {
                System.out.println("请输入一个1-100之间的数字");
                int num = scanner.nextInt();
                if (random < num) {
                    System.out.println("您输入的数字比正确数字大");
                } else if (random > num) {
                    System.out.println("您输入的数字比正确数字小");
                } else {
                    System.out.println("恭喜您，猜对了！");
                    break;
                }
                System.out.println("您还有" + (i - j - 1) + "次机会");
            }
            System.out.println("如果您要继续游玩请输入y");
            input=scanner.next();
        }while ("y".equals(input));
    }
}
